<script type="text/JavaScript">

function checkform() {
	d=document.groupForm;
	if (d.streetno.value == "" || d.streetname.value == "" || d.streettype.value == "" || d.suburb.value == "" || d.postcode.value == "") {
		alert("Please complete all required fields.");
		return false;
	}
	
	return true;
}

function checkChoreForm1() {
	d=document.choreForm;
	if (d.billName.value == "") {
		alert("Please enter a name for the chore.");
		return false;
	}
	validDate=/^\d{2}\/\d{2}\/\d{4}$/
	if (!validDate.test(d.dueDate.value)) {
		alert("Please enter the due date in the correct format: DD/MM/YYYY");
		return false;
	}
	return true;
}

function checkBillForm1() {
	d=document.billForm;
	validTotal1=/^([0-9])+\.([0-9]{2})$/;
	validTotal2=/^([0-9]{1,7})$/;
	if (d.billName.value == "") {
		alert("Please enter a name for the bill.");
		return false;
	}
	if (validTotal1.test(d.billTotal.value) || validTotal2.test(d.billTotal.value)) {
		validDate=/^\d{2}\/\d{2}\/\d{4}$/
		if (!validDate.test(d.dueDate.value)) {
			alert("Please enter the due date in the correct format: DD/MM/YYYY");
			return false;
		}
		return true;
	}
	
	alert("Please enter a valid amount for the Total.");
	return false;
}

function checkDistroTotals(members, billTotal) {
	d=document.billDistro;
	validTotal1=/^([0-9])+\.([0-9]{2})$/;
	validTotal2=/^([0-9]{0,7})$/;
	runningTotal=0;
	// first parse to make sure numerical values in all fields
	if (d.member1) {
		if (validTotal1.test(d.member1.value) || validTotal2.test(d.member1.value)) {
			runningTotal=runningTotal + (d.member1.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	if (d.member2) {
		if (validTotal1.test(d.member2.value) || validTotal2.test(d.member2.value)) {
			runningTotal=runningTotal + (d.member2.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	if (d.member3) {
		if (validTotal1.test(d.member3.value) || validTotal2.test(d.member3.value)) {
			runningTotal=runningTotal + (d.member3.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	if (d.member4) {
		if (validTotal1.test(d.member4.value) || validTotal2.test(d.member4.value)) {
			runningTotal=runningTotal + (d.member4.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	if (d.member5) {
		if (validTotal1.test(d.member5.value) || validTotal2.test(d.member5.value)) {
			runningTotal=runningTotal + (d.member5.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	if (d.member6) {
		if (validTotal1.test(d.member6.value) || validTotal2.test(d.member6.value)) {
			runningTotal=runningTotal + (d.member6.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	if (d.member7) {
		if (validTotal1.test(d.member7.value) || validTotal2.test(d.member7.value)) {
			runningTotal=runningTotal + (d.member7.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	if (d.member8) {
		if (validTotal1.test(d.member8.value) || validTotal2.test(d.member8.value)) {
			runningTotal=runningTotal + (d.member8.value * 1);
		}
		else {
			alert("You must enter numerical values only.");
			return false;
		}
	}
	
	if (members > 8) {
		alert("There was an error processing the data. Please contact the administrator.");
		return false;
	}
	
	if (runningTotal == billTotal) {
		return true;
	}
	alert("All shares must add up to the bill total of $" + billTotal + ". Current total is $" + runningTotal + ".");
	return false;
}

</script>